﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XinYi.CrookedShow.Core;
using XinYi.CrookedShowMode;

namespace XinYi.CrookedTopShow.DAL
{
    public class SMSInfoRepository
    {
        /// <summary>
        /// 将验证码和电话保存至数据库
        /// </summary>
        /// <param name="sMSInfo"></param>
        /// <returns></returns>
        public int InsertSMSInfo(SMSInfo sMSInfo)
        {
            DateTime dateTime = DateTime.Now.AddMinutes(5);
            string sql = @"insert into SMSInfo values(Code=@Code, TelPhone=@TelPhone, CreateTime=" + DateTime.Now + ", ExpireTime=" + dateTime+")";
            return  DapperHelper<SMSInfo>.Execute(sql, sMSInfo);
        }
        /// <summary>
        /// 查询电话和验证码是否正确
        /// </summary>
        /// <param name="sMSInfo"></param>
        /// <returns></returns>
        public int SelCodePhone(SMSInfo sMSInfo)
        {
            DateTime dateTime = DateTime.Now.AddMinutes(5);
            string sql = @"select COUNT(1) from SMSInfo where Code=@Code and TelPhone=@TelPhone and ExpireTime=" + DateTime.Now + "";          
            return Convert.ToInt32( DapperHelper<SMSInfo>.QueryScalar(sql, sMSInfo));
        }
    }
}
